//{====================================================================================
//! @file Var1taskDotv.c
//! @date    2013-09-29 20:44
//! @author Andrianov Georgiy <egor.andrianov81@gmail.com>
//!
//! Finding numbers of binary sequence, where there are no
//! two following units
//!
//! @par The programme enters number
//!      It needs to output n+1 strings with number b(n,k)
//!      where n - length of sequence
//!            k - number of units
//}====================================================================================

#include <stdio.h>
#include <math.h>

long binary(int a, int b);
long factorial(int a);
long combination(int n, int k);

int main()
{
    int n = 0, i = 0, j = 0;
    printf("Enter number\n");
    scanf("%i", &n);
    for (i = 0; i <= n; i++)
        {
            if (i % 2 == 0)
            {
                for (j = 0; j <= (i / 2); j++)
                {
                    printf("%i ", binary(i, j));
                }
            }
            else
            {
                for (j = 0; j <= (i / 2) + 1; j++)
                {
                    printf("%i ", binary(i, j));
                }
            }
            printf("\n");
        }
    return 0;
}

//! binary - Finding numbers of binary sequence, where there are no
//! two following units
//!
//! @param      a   length of sequence
//! @param      b   number od units
//!
//! @return         Number such sequence

long binary(int a, int b)
{
    if ((a == 0) || (b == 0))
    {
    return 1;
    }
    else
    {
        if ((b == 1) || (a == 1))
        {
            return a;
        }
        else
        {
            return combination(a, b) - combination(a - 1, b - 1);
        }

    }
}

//! combination - calculates the binomial coefficient
//!
//! @param      n
//! @param      k
//!
//! @return     value of the binomial coefficient

long combination(int n, int k)
{
    return factorial(n)/(factorial(k)*factorial(n - k));
}

//! factorial - calculates factorial
//!
//! @param      a
//!
//! @return     value of factorial

long factorial(int a)
{
    int i = 0;
    long s = 1;
    for (i = 1; i <= a; i++)
    {
        s = i * s;
    }
    return s;
}






